<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<a href="/a">跳转</a>
	<div id="app"></div>
	<form action="/a" id="login_form">
		用户名<input type="text" name="username">
		密码<input type="password" name="password">
		<input type="submit" value="提交">
	</form>
	<script type="text/javascript">
		var a = document.querySelector("a");
		var login_form = document.querySelector("#login_form")
		var app = document.querySelector("#app")
		a.onclick = function(event){
			alert("你点击了a")
			event.preventDefault();
		}
		login_form.onsubmit = function(event){
			var username = document.querySelector("#login_form input[name=username]").value;
			var pwd = document.querySelector("#login_form input[name=password]").value;
			if(username === "moyu" && pwd === "123123"){
				//隐藏登录界面
				login_form.style.display = "none";
				//插入用户信息
				var newDiv = document.createElement("div");
				newDiv.innerText = "欢迎你,"+username;
				app.append(newDiv);
			}else{
				alert("用户信息不合法")
			}
			event.preventDefault();
			// alert(username+":"+pwd);
		}
	</script>
</body>
</html>